package com.int_tech.utils;

import com.fasterxml.uuid.Generators;

import java.util.UUID;

/**
 * Created by Administrator on 2017/10/16.
 */
public class GetUUID {
    public static String getIdByUUId() {
        int machineId = 1;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if(hashCodeV < 0) {//有可能是负数
            hashCodeV = - hashCodeV;
        }
        // 0 代表前面补充0
        // 4 代表长度为4
        // d 代表参数为正数型
        return machineId + String.format("%015d", hashCodeV);
    }

    public static String getId(){
        return Generators.timeBasedGenerator().generate().toString();
    }

    public static void main(String[] args) {
        System.out.println(getIdByUUId());
        System.out.println(getId());
    }
}
